002 plc program structure
在本次讲座中,让我们看一下将运行我们的系统的 C 程序。
In this lecture Let's take a look at our C program that's going to be running our system.
所以我现在在虚拟机中,我将继续加载 Peale 的 C-3 程序,我们不会详尽地介绍该程序,因为它不是 C 编程课程,但我确实需要您熟悉这个程序的布局,因为当你编程时,它会派上用场,快速解析这个程序,并假设你已经学习了我的第一门和第二门 C 课程《从头开始的 C 编程》和《实用 C 编程》 。
So I'm in the virtual machine now and I'm going to go ahead and load up the Peale's C-3 program and we're not going to go exhaustively through this program because it's not a C programming course but I do want you to be familiar with the layout of this program because it will come in handy as you're programming your miles to just very quickly parse through this and assuming you've already taken my first and second c courses C programming from scratch and practical C programming.
这对你来说已经是老生常谈了,所以你甚至可以跳过这个讲座,但我建议你至少复习一下,所以我们开始吧。
This is all going to be pretty old hat to you so you might even just skip through this lecture but I'd recommend you take the refresher at least So here we go.
在后两者中,我们在这里所做的唯一事情就是将所有不同的梯子一路向下调用,然后将溢出陷阱设置为永久解锁。
In latter two the only things that we're doing in here are a calling all of our different ladders all the way down and then B we're setting our overflow trap to permanent unlatch.
因此,每当我们的数学梯级之一以某种方式尝试除以零或创建某种奇怪的数字时,就会发生这样的情况。
So what that does is any time one of our math rungs would somehow try to divide by zero or create some kind of strange number.
这可以防止我们的 PLCC 在关闭锁定时出错,因为如果您想防止这种情况发生,您必须在梯子 2 的最后一级执行 Colan 五斜线零解锁操作。
This prevents our PLCC from faulting in shutting down locking as Colan five slashes zero unlatched is something that you have to do at the very last rung of ladder 2 if you want to prevent that from happening.
这只是您必须了解的有关 R.S. 的事情之一。
So that's just one of those things you have to know about R.S.
逻辑在处理器中的 500 种编程。
logic's 500 programming in processors.
后两者就是这样。
So that's it for latter two.
让我们进入天梯3。
Let's go into Ladder 3.
这是我们的 IO 所以我们在这里设置我们的输入。
And this is our IO So here we're setting up our inputs.
这是我们的流量开关。
There's our flow switch.
FS 之一,您会注意到的是,我实际上使用内部存储器注册表中的位作为输入设备,而不是我应该在真正的 PC 编程 I O 地址上使用的位,例如冒号的 0 斜杠零。
FS one and something that you're going to notice is that I'm actually using bits in the internal memory registry as input devices rather than what I should be using on a real P C programming I O addresses like I Colon's 0 slash zero.
这将是一个真实的物理输入设备地址。
That would be a real physical input device address.
但由于我们将仅在仿真中使用它,并且我希望能够使用一些仿真逻辑从程序内控制输入设备,因此我只使用这些标准位地址而不是 IO 地址。
But since we're going to be using this solely on emulate and I want to be able to control the input devices from within the program using some simulation logic I'm just using those standard bit addresses instead of IO addresses.
因此,这些将是进出系统的实际物理输入和输出。
So these would be the actual physical inputs and outputs coming in and out of the system.
这将是一个输入。
This would be an input coming in.
这是我们的 6 缸恼人阀门。
And here are our 6 cyl annoyed valves.
所以这些将是在这里输出的输出。
So those would be outputs going out and down here.
这将是我们的泵即将熄灭。
This would be our pump going out.
所以在这里我们将控制我们的泵,然后我们还有一些模拟。
So here we would be controlling our pump and then we also have a little bit of analog.
所以你将再次认识我的标准逻辑,而不是使用输入。
So you're going to recognize my standard logic here again instead of using an input.
我使用一个整数来模拟传入的原始信号。
I'm using an integer to simulate that raw signal coming in.
这是我们的压力变送器。
This is for our pressure transmitter.
我们会说这是为缩放而设置的模块,因此从 0 到 16 383,我们会将其从 0 PSII 缩放到 20 PSII 并将其存储为浮点数。
We're going to say it's the modules set up for the scaling so 0 to 16 383 and we're going to be scaling that from zero PSII up to 20 PSII and storing that as a float.
然后只是为了良好的实践,即使它确实没有发挥作用,并且这个程序或在这个场景中我已经得到了模拟保护。
Then just for good practice even though it really doesn't come into play and this program or in this scenario I've got my overunder analog protection.
因此,如果我们收到低于最小值或高于最大值的奇怪信号,我们将继续最小化或最大化缩放值 F-8 零。
So if we should get a strange signal coming in below the minimum or above the maximum We're going to go ahead and minimize or maximize the scaling on our scaled value F-8 zero.
我正在以同样的方式处理我们的第二个压力传感器。
And I'm treating our second pressure transmitter the same way.
在这个梯级上。
And on this rung.
这实际上并不是我知道我正在减去我的压力,这样我就可以产生压差并显示这两者之间的差异。
This isn't actually I know I'm subtracting my pressures so that I can create a differential pressure and show what the differences between those two.
然后我将差异的绝对值存储在这里。
And then I'm storing the absolute value of that difference right here.
因此,无论我得到正差异还是负差异,我都会将其转化为正差异,然后将其存储起来。
So whether I get a positive difference or a negative difference I'm going to turn it into a positive difference and then I'm going to store that.
所以我总是会知道我的差异是多少,而且它总是一个正值。
So I'm always going to know what my differential is and it's always going to be a positive value.
然后我在后者中发生的唯一另一件事是我对液位变送器的缩放,并且设置与我的两个压力完全相同。
And then the only other thing I have happening in this latter is my scaling for my level transmitter and that set up exactly the same as my two pressures.
这就是本次运行的内容。
So that's it for this run.
让我们进入这里的警报信。
Let's jump into alarm's letter for here.
我只设置了四个闹钟。
I've only got four alarms set up.
我的第一个是高压警报器。
My first one is a high pressure alarm.
然后我还有一个低流量警报来保护我的泵。
Then I also have a low flow alarm which is protecting my pump.
我有一个低低的储水箱。
I have a storage tank low low.
然后我有一个高高的储罐,我的所有警报都是使用 PLCC 中非常熟悉的逻辑来设置的。
And then I have a storage tank high high and all of my alarms are set up using very familiar logic from PLCC one here.
我正在检查电平,看看它是否实际上大于我将从您要开发的 HDMI 发送的设定点。
I'm checking the level to see if it's actually greater than a set point that I am going to be sending in from the HDMI that you're going to be developing.
超过该设定点五秒后,我将触发两个不同的位。
And after five seconds of it being over that set point I'm going to trigger two different bits.
我将触发一个警报位和一个通知位,该警报位将在程序中发挥作用以锁定事物。
I'm going to trigger an alarm bit and a notification bit this alarm bit is going to be functioning within the program to lock things out.
这个通知位可能会在您的 HDMI 中用于通知操作员发生了某些事情,然后这两者都可以通过警报重置来重置,或者您可以使用警报静音来简单地关闭通知位。
Potentially this notification bit is going to be used in your HDMI to notify the operator that something's happened and then both of these can be reset by an alarm reset or you can use an alarm silence to simply turn off the notification bit.
即使警报状态仍然存在。
Even though the alarm condition will remain.
这就是所有这些警报的设置方式。
And that's how all of these alarms are set up.
该梯子中发生的唯一另一件事是在梯级 16 上,我正在设置一个关键警报位,它告诉我们是否有高压警报或低流量警报,其中任何一个都将被视为严重警报该系统并将关闭该系统。
The only other thing happening in this ladder is down here on rung 16 I'm setting a critical alarm bit which is telling us if we either have a high pressure alarm or a low flow alarm either one of those would be considered a critical alarm to this system and would shut the system down.
这就是当我们进入控制梯时警报声音更大的原因。
So that's it for the alarms louder when we go into the control ladder.
我们在这里所做的就是控制七个数字输出设备,因此我们有一个泵,然后有六个细胞烦人的阀门。
All we're doing here is controlling our seven digital output devices so we have one pump and then we have six cell annoyed valves.
这些将有不同的模式。
And those are going to have different modes.
我们的每一个数字输出设备都可以关闭。
Each one of our digital output devices can be either off.
它可以是手动模式,也可以是自动模式。
It can be in hand mode or it can be an automatic mode.
在这里我们基本上控制了这个。
And here we're basically controlling this.
在这种情况下,只要该电磁阀处于手动模式,我们希望它运行,就可以打开它。
To turn it on in this case any time that this solenoid valve is in hand mode we want it to run.
否则,如果系统正在运行并且反冲洗正在运行,那么我们将打开它。
Otherwise if the system is running and the backwash is running then we're going to turn it on.
因此,这里的这个子分支实际上为我们提供了自动控制,我们正在评估本次运行中是否处于手动模式,但我们不必评估本次运行中是否处于自动模式,因为我编写的逻辑是,如果系统正在运行,那么所有设备都必须处于自动模式,因此该位的存在告诉我们,不仅我们所有设备都处于自动模式,而且系统也处于自动模式实际上也在运行。
So this subbranch down here is actually giving us our automatic control we're evaluating to see if we're in hand mode on this run but we don't have to evaluate to see if we're an auto mode in this run because the way that I have the logic written if the system is running then all of the devices have to be in automatic mode so just the presence of this bit is telling us that not only are we in automatic mode on all of our devices but that the systems actually running as well.
然后在它们的右侧将是每个设备在自动模式下通电所需的任何条件。
And then to the right of they're just going to be whatever conditions are necessary for each of these devices to energize in automatic mode.
这就是进入梯子 6 的每个单独设备沿该梯子一直发生的情况。
So that's what's happening all the way down this ladder for each individual device coming into a ladder 6.
这是我们实际在每个设备上设置模式的地方,无论是手动模式还是音频模式。
This is where we're actually setting the mode on each of those devices whether it's in hand off or audio.
我们已经从死亡按钮中设置了不同的条件。
And we've got push buttons from the demise setting the different conditions.
显然,这些位将要使用,然后我们还有一个第一通过位,每当 PRC 程序首次启动时,它就会关闭所有内容,这就是第一通过位的作用。
And these are bits that are going to be working with obviously and then we also have a first pass bit which is turning everything off whenever the PRC program is first started so that's what this first pass bit does.
它仅在程序运行时的第一次扫描时激活,以确保我们所有的设备不会以手动模式或其他疯狂的模式启动。
It only energizes on the very very first scan when the program is run just to make sure that all of our devices don't start off in hand mode or something crazy.
我们希望系统启动时一切都关闭。
We want everything to be off whenever the system starts.
如果我们一直滚动到这里,您会看到有很多这样的梯级。
And if we scroll all the way down here you're going to see there are a lot of those rungs.
但这没关系,因为我们的每一种数字输出设备都必须发生三个不同的过程。
But that's OK because there's three different processes that have to happen for every one of our digital output devices.
然后我们来到了最后一个梯级,这里是 21 级。
And then we're down in the last rung here this is rung 21.
我们还将这一切始终设置为自动位。
We're also setting this all always in auto bit.
一旦我们看到所有不同的设备都设置为自动模式,这将成为启动系统的先决条件,这就是我们创建该位的原因。
Once we see that all of our different devices are set into auto mode and that's going to be a prerequisite for starting the system so that's why we're creating that bit.
这就是《天梯 6》的内容。
So that's it for Ladder 6.
让我们进入第7梯子。
Let's go into ladder 7.
我并不打算解释这里发生的一切。
And I'm not really going to explain everything that's happening in here.
这不是秘密。
It's not a secret.
但这与我们将要处理的事情并不真正相关。
But it's just not really relevant to what we're going to be working with.
这是我创建模拟逻辑的地方,它通过 Arment 为我们的系统模拟现实世界的工作。
This is where I create the simulation logic which is simulating a real world working can by Arment for our system.
因此,当我们在下一堂课中打开这个东西并运行它时,我们将看到我们的水箱正在排水和填充,并且过滤器中的压力正在增加。
So when we turn this thing on in the next lecture and we run it we're going to see that our tank is draining and filling and pressure is building up in the filter.
好吧,我们没有真正的过滤器,也没有真正的水箱。
Well we don't have a real filter we don't have a real tank.
那么这是怎么发生的呢。
So how is that happening.
好吧,实际上是后者让这一切发生了。
Well well this is the latter that's actually making all of that happen.
所以这是一门有吸引力的 C 编程课程,我不会让您感到厌烦。
So this is an appeal C programming course I'm not going to bore you with.
你知道我为什么要加上这个,然后把那个一直往下去掉。
You know why I am adding this and taking that out all the way down.
但你知道,如果你好奇地想浏览这里,我们非常欢迎你,而且我已经给所有内容贴上了标签,这样你就能明白,这并不是真正值得在梯子 8 中进行大量解释的东西。
But you know you're more than welcome if you're curious to go through here and I've labeled everything so you'll be able to figure it out it's just not something that really merits a lot of explanation in ladder 8.
这是我们设置系统模式的地方。
This is where we're setting our system mode.
我们的系统要么运行,要么不运行,我们将有一个启动按钮和停止按钮来控制它,然后我们将仅使用标准数字逻辑。
Our system is either going to be running or it's not going to be running and we're going to have a start push button and stop push button to control that and then we're going to be using just standard digital logic.
我们将使用 Trigger 的 Holdens 和中断来使这些事情发挥作用。
We're going to be using Trigger's Holdens and interrupts to make these things work.
所以这确实是我们正在控制的部分。
So this is really the bit that we're controlling.
这两个只是为其创建一个触发器和中断。
And these two are just creating a trigger an interrupt for it.
但这是所有动作发生的地方都是错误的。
But this is the wrong where all the action happens.
我们不需要一个不运行的系统,我们只需要一点。
We don't need a system not running bit we just have one bit.
它要么通电并运行,要么断电,在这种情况下它显然没有运行。
Either it's energized and running or it's de-energize in which case it's obviously not running.
非常简单。
So very simple.
然后我们现在将跳入整个程序中的梯子 9 反洗。
Then we're going to jump into ladder 9 backwash now out of our whole program.
这可能是最困难的,因为这里确实发生了很多不同的事情。
This one is probably the most difficult because there's really a lot of different stuff going on here.
对于第一个错误,我们所做的就是让操作员能够使用几个不同的按钮锁定反冲洗循环并防止系统自动反冲洗。
What we're doing on this first wrong is we're giving the operator the ability to lock out the backwash cycle and prevent the system from back washing automatically using a couple of different buttons.
然后,在代码的下一部分中,我们实际上正在检查系统的压差是否大于我们的设定点。
Then in this next section of code now we're actually checking to see based on the differential pressure of the system being greater than our set point.
如果持续五秒钟,那么我们将触发待处理的反洗,并且我们不会立即触发反洗,因为除非水箱已满,否则我们不想进行反洗。
If it is for five seconds then we're going to trigger the backwash pending and we are not going to trigger an immediate backwash because we don't want to do a backwash unless the tank is full.
我们需要从水箱中排出大量的水。
We are going to need to drain a lot of water out of our tank.
因此,现在一旦我们检测到压差很高,我们就会启用此位。
So for now once we detect that our differential pressure is high we're going to enable this bit.
我们将给它通电并表示有待进行反冲洗。
We're going to energize it and say that there's a backwash pending.
然后,当时机成熟时,我们将对此进行评估,然后我们将根据是否有待处理的问题实际开始反洗。
And then when the time comes we'll evaluate that and then we'll actually start the backwash based on whether there's one pending or not.
除了压差太高之外还有另一种方法。
And another way aside from the differential pressure getting too high.
我们触发反冲洗的另一种方法是使用位于 Chimay 上的手动反冲洗按钮。
Another way that we could trigger a backwash is with a manual backwash pushbutton which is going to be located on the Chimay.
所以这些可以自动触发,也可以手动触发。
So these can be triggered automatically or it can be triggered manually.
然后,当我们现在到达这里时,我们实际上将根据水箱液位处于某个安全水平来触发反冲洗循环,在这种情况下,一旦水箱液位足够高并且反洗正在等待,持续两秒钟,然后我们将触发反洗。
Then when we get down here now we're actually going to be triggering the backwash cycle based upon the tank level being at a certain safe level in this case we've got it set to 80 percent once the tank level is high enough and a backwash is pending and that lasts for two seconds then we're going to trigger a backwash.
然后在下一行中,我们根据触发器和保持来控制反冲洗循环的运行,并且它将继续运行,直到反冲洗计时器用完为止。
And then in this next line we're controlling that the backwash cycle is running based on our trigger and a hold in and that's going to keep running until our backwash timer runs out.
唯一可能中断此循环的其他事情是有人阻止系统运行或出现严重警报。
The only other things that could interrupt this cycle would be somebody stopping the system from running or a critical alarm showing up.
那么我们这里就有了反冲洗循环计时器,它将持续 60 秒。
So then we've got our backwash cycle timer here which is going to last for 60 seconds.
然后,这个梯子内发生的其他事情是,我们将发送一个计算结果,计算反冲洗周期还剩下多少时间,因此我们将花费 60 秒,然后减去这个计时器的累计并告诉还剩多少秒。
Then the other things that are happening inside this ladder is that we're going to be sending out a calculation of how much time is left in our backwash cycle so we're going to take our 60 seconds and we're going to subtract out this timer's accumulation and tell how many seconds are left.
因此,这将是运营商利益的实时倒计时。
So that's going to be a live count down for the operators benefit.
我们还将计算反冲洗的周期。
We're also going to be counting the cycles of the backwash.
因此,每次我们进行反冲洗时,我们都会在七分八中添加一,这将跟上我们在执行此操作时所做的反冲洗次数。
So every time we do a backwash we're going to add one to in seven eight and that's going to keep up with how many backwash as we've done while we're doing that.
我们还将在每次系统反冲洗时记录数据。
We're also going to be logging data every time our system back washes.
因此,这将是我们的最后一个项目,但我们将创建一个数据日志,每次发生反冲洗时,该日志都会存储来自海洋的一些相关值,因此这将是按需数据日志。
So this is going to be our very last project but we're going to be creating a data log that's going to be storing some relevant values from the sea every time the backwash happens so that's going to be an on demand data log.
这就是我们真正激发活力的地方。
And here's where we're actually energizing the bit.
这将告诉 HDMI 将数据记录在这里。
This is going to tell the HDMI to log the data down here.
我们正在管理反冲洗周期计数。
We're managing our backwash cycle count.
因此,如果操作员想要重置,他可以按住此按钮五秒钟,此时我们的循环计数将重置为零。
So if the operator wants to reset that he can hold down this button for five seconds at which time our cycle count will be reset to zero.
所以这个梯子 10 中发生的很多事情是我们的水箱液位控制,我们有两种模式。
So a lot going on in this ladder ladder 10 is our tank level control and we've got two modes.
我们要么有填充模式,要么有排水模式,它只能由这一位来控制,这只是一个水箱填充位。
We've either got a fill mode or a drain mode and it's only going to be controlled by this one bit which is just a tank filling bit.
如果我们的水箱处于胶片模式,我们将控制该位以自动模式打开或关闭泵。
And we're going to control that bit to turn the pump on or off in automatic mode if our tank is in film mode.
显然,泵将运行,如果没有通电,那么我们不需要填充油箱,因此我们的泵将不会运行。
Obviously the pump is going to be running and if that's not energized then we don't need to fill our tank so our pump is not going to be running.
这就是这里发生的情况,我们正在评估级别来决定何时开始填充。
So that's what's happening in here we're evaluating the level to decide when to start filling.
我们还在评估液位以确定何时停止填充。
And we're also evaluating the level to determine when to stop filling.
这就是这个梯子的内容。
That's it for this ladder.
然后我们又得到了两个字母来看看梯子 11 是一个小时计。
Then we've get two more letters to look at Ladder 11 is an hour meter.
这将跟踪我们的系统在正常模式下运行的时间。
This is going to be tracking how much time our system spends running in normal mode.
因此,如果我们的系统正在运行并且我们没有进行回洗,那么我们将启用此滞后时间位,这将告诉我们应该捕获什么时间。
So if our system is running and we are not back washing then we're going to enable this lag time bit which is going to tell us what time we should be capturing.
因此,每当协同作用时,我们都会使用 TiVo 计时器来跟踪秒数,我们会将秒数存储到这个整数中,然后将这些秒数累加到分钟中,并将其存储到另一个整数中。
So anytime that synergize we're going to be tracking seconds with this our TiVo timer we're going to be storing the seconds into this integer then we're going to be accumulating those seconds into minutes and storing that into another integer.
我们将把这些分钟累积成小时,然后将其存储到此处的另一个整数中。
We're going to be accumulating those minutes into hours storing that into another integer right here.
然后我们将把这些时间存储为数千小时。
And then we're going to be storing those hours into thousands of hours.
这里还有另一个整数,就像我们对反洗循环所做的那样,因为我们有一个小时计。我们还将让操作员能够通过按住按钮五秒钟来重置仪表,这将擦除我们所有的价值观。
And yet another integer here and like just like we did for the backwash cycles because we have an hour meter We're also going to give the operator the ability to reset our meter by holding in a push button for five seconds which is going to wipe out all of our values.
这将我们引向最后的梯子 12 号梯子,这个梯子看起来又大又复杂,但它实际上几乎没有任何作用。
And that leads us to our final ladder ladder 12 and this ladder looks big and complicated but it really doesn't do hardly anything.
所有这些梯子的目的都是为了让我们可以查看或控制所有这些不同的位,并且我们可以从一个地方设置整个系统中所有这些不同的整数和浮点数。
All this ladders for is so that we can look at or control all of these different bits and all of these we can set all of these different integers and floats throughout the system all from one place.
因此,我们不必进入反冲洗并设置某些内容,然后进入 IO 并设置某些内容,然后进入 agio 方式设置六到七项内容,我们可以从“回顾”选项卡中完成所有操作,在下一讲中我们将进行运行这个系统,我将向您展示我如何使用它。
So rather than having to go into backwash and set something then go into IO and set something and then go into agio way to set six or seven things we can do it all right here from the review tab and in the next lecture we're going to be running this system and I'm going to show you how I use this.
所以你看看它就很草率。
So you look at it it's sloppy.
这是一团糟,你知道很多东西要看。
It's a big mess and it's you know kind of a lot to look at.
现在你明白为什么我们需要 HMO 眼睛了,否则我们将不得不使用这样的东西来控制我们的系统。
Well now you see why we need HMO eyes because otherwise we would have to use things like this to control our system.
这真是让人头疼。
And that's a pain in the butt.
没有人愿意这样做。
Nobody wants to do that.
就是这样了。
So that's it.
这就是整个程序的流程。
That's the walk through of this whole program.
在下一堂课中,您将看到它的运行。
And in the next lecture you're going to see it run.
那一会儿见。
I'll see you then.
干杯。
Cheers.